<?php
/*
* $Author ：PHPYUN开发团队
*
* 官网: http://www.phpyun.com
*
* 版权所有 2009-2018 宿迁鑫潮信息技术有限公司，并保留所有权利。
*
* 软件声明：未经授权前提下，不得用于商业运营、二次开发以及任何形式的再次发布。
 */
class admin_company_job_controller extends adminCommon{
	
	function set_search(){
		include PLUS_PATH."/com.cache.php";
        foreach($comdata['job_type'] as $k=>$v){
		   $comarr[$v]=$comclass_name[$v];
        }
        foreach($comdata['job_salary'] as $k=>$v){
		   $comar[$v]=$comclass_name[$v];
        }
		include(CONFIG_PATH."db.data.php");
		$source=$arr_data['source'];
		$this->yunset('source',$source);
		$search_list[]=array("param"=>"status","name"=>'招聘状态',"value"=>array("1"=>"已下架","2"=>"发布中","3"=>"置頂"));
 		$this->yunset("search_list",$search_list);
	}
    //统计接口开始
	function getzhaopin_action(){
        // 指定允许其他域名访问
        header('Access-Control-Allow-Origin:http://47.104.30.217:8080');
        // 响应类型
        header('Access-Control-Allow-Methods:GET');
        // 响应头设置
        header('Access-Control-Allow-Headers:x-requested-with,content-type');
        $data = $this->getEverything( 'zhaopin' );
        echo json_encode($data);die;
    }

    function getruzhi_action(){
	    // 指定允许其他域名访问
        header('Access-Control-Allow-Origin:http://47.104.30.217:8080');
        // 响应类型
        header('Access-Control-Allow-Methods:GET');
        // 响应头设置
        header('Access-Control-Allow-Headers:x-requested-with,content-type');
        $data = $this->getEverything( 'ruzhi' );
        echo json_encode($data);die;
    }

    function getjifen_action(){
        // 指定允许其他域名访问
        header('Access-Control-Allow-Origin:http://47.104.30.217:8080');
        // 响应类型
        header('Access-Control-Allow-Methods:GET');
        // 响应头设置
        header('Access-Control-Allow-Headers:x-requested-with,content-type');
    $data = $this->getEverything( 'jifen' );
    echo json_encode($data);die;
    }
    //统计接口结束

	function index_action(){
		//java验证
		$this->cheakjava();

 		$this->set_search();
		$time = time();
        $wheres = "1 ";
			extract($_GET);
			if(trim($_GET['keyword'])!=""){
			    $wheres .="and  CONCAT(`com_name`,`name`) like '%".trim($_GET['keyword'])."%'";
				$urlarr['keyword']=$_GET['keyword'];
			}
        if($_GET['status']!=""){
			if($_GET['status']!=3){
				$wheres .=" and  `status` = '".$_GET['status']."'";
			}else{
				$wheres .=" and  `xsdate` is not null and `xsdate`>".$time;
			}
            $urlarr['status']=$_GET['status'];
        }
		$urlarr['page']="{{page}}";
		$urlarr['key']=$_GET['key'];
        $wheres .= ' order by `sdate` DESC';
		$pageurl=Url($_GET['m'],$urlarr,'admin');
		$rows=$this->get_page("company_job",$wheres,$pageurl,$this->config['sy_listnum']);
		include PLUS_PATH."job.cache.php";
		include PLUS_PATH."industry.cache.php";
		include PLUS_PATH."com.cache.php";
		if(is_array($rows)){
			$jobids=array();
		    foreach ($rows as $v){ 
				$jobids[]=$v['id'];
				$uid[]=$v['uid'];
		    }
			$useridjob=$this->MODEL('job')->GetUseridJob(array("`job_id` in(".pylode(',',$jobids).")",'is_browse'=>1),array('field'=>"count(id) as num,`job_id`",'groupby'=>'job_id'));			
			
			$msgnum=$this->MODEL('resume')->GetUserMsgNums(array("`jobid` in(".pylode(',',$jobids).")"),array('field'=>"count(id) as num,`jobid`",'groupby'=>'jobid')); 
			
			$member = $this->obj->DB_select_all("member","`uid` IN (".@implode(',',$uid).")","`uid`,`status`");
			$company = $this->obj->DB_select_all("company_statis","`uid` IN (".@implode(',',$uid).")","`uid`,`rating_name`");
			
			foreach($rows as $k=>$v){
				if($v['xsdate']>1000){
					$rows[$k]['xstime']=date("Y-m-d",$v['xsdate']);
				}
				if($v['rec_time']>1000){
					$rows[$k]['recdate']=date("Y-m-d",$v['rec_time']);
				}
				if($v['urgent_time']>1000){
					$rows[$k]['eurgent']=date("Y-m-d",$v['urgent_time']);
				}
				
				$rows[$k]['browseNum']=$rows[$k]['inviteNum']=0;
				$rows[$k]['edu']=$comclass_name[$v['edu']];
				$rows[$k]['exp']=$comclass_name[$v['exp']];
				if($v['job_post']){
					$rows[$k]['job']=$job_name[$v['job_post']];
				}else{
					$rows[$k]['job']=$job_name[$v['job1_son']];
				}

				$rows[$k]['salary']=$comclass_name[$v['salary']];
				$rows[$k]['type']=$comclass_name[$v['type']];

				if($v['urgent_time']>$time){
					$rows[$k]['urgent_day'] = ceil(($v['urgent_time']-$time)/86400);
				}else{
					$rows[$k]['urgent_day'] = "0";
				}
				if($v['xsdate']>$time){
					$rows[$k]['xs_day'] = ceil(($v['xsdate']-$time)/86400);
				}else{
					$rows[$k]['xs_day'] = "0";
				}
				if($v['rec_time']>$time){
					$rows[$k]['rec_day'] = ceil(($v['rec_time']-$time)/86400);
				}else{
					$rows[$k]['rec_day'] = "0";
				} 
				foreach($useridjob as $val){
					if($val['job_id']==$v['id']){
						$rows[$k]['browseNum']=$val['num'];
					}
				}
				foreach($msgnum as $val){
					if($val['jobid']==$v['id']){
						$rows[$k]['inviteNum']=$val['num'];
					}
				}
				foreach($member as $key=>$value){
					if($value['uid']==$v['uid']){
						$rows[$k]['c_status']=$value['status'];
					}
				}
				foreach($company as $key=>$value){
					if($value['uid']==$v['uid']){
						$rows[$k]['rating_name']=$value['rating_name'];
					}
				}
			}
		}
		$adtime=array('1'=>'今天','3'=>'最近三天','7'=>'最近七天','15'=>'最近半月','30'=>'最近一个月');
		$adtime=array('1'=>'今天','3'=>'最近三天','7'=>'最近七天','15'=>'最近半月','30'=>'最近一个月');
		$this->yunset("adtime",$adtime);
		$this->yunset("page",$_GET['page']);
		$this->yunset("get_type", $_GET);
		$this->yunset("wheres", $_GET['keyword']);
		$this->yunset("status", $_GET['status']);
		$this->yunset($this->MODEL('cache')->GetCache(array('job','hy')));
		$this->yunset("rows",$rows);
		$this->yunset("time",$time);
		$this->yuntpl(array('admin/admin_company_job'));
	}
    
	function show_action(){

		include(CONFIG_PATH."db.data.php");		
		$this->yunset("arr_data",$arr_data);
		$this->yunset($this->MODEL('cache')->GetCache(array('city','hy','com','job')));
		if($_GET['id']){
			$show=$this->obj->DB_select_once("company_job","id='".$_GET['id']."'");
			$show['lang']=@explode(',',$show['lang']);
			
			if($row['three_cityid']){
				$row['circlecity']=$row['three_cityid'];
			}else if($row['cityid']){
				$row['circlecity']=$row['cityid'];
			}else if($row['provinceid']){
				$row['circlecity']=$row['provinceid'];
			}
			$this->yunset("show",$show);
			$this->yunset("lasturl",$_SERVER['HTTP_REFERER']);
		}

		if($_POST['update']){
			

			$_POST['lang']=@implode(',',$_POST['lang']);
 
 			$_POST['description'] = str_replace("&amp;","&",$_POST['content']);
			$_POST['lastupdate'] = time();
			$lasturl=$_POST['lasturl'];
			unset($_POST['update']);unset($_POST['content']);unset($_POST['lasturl']);
			 
			if($_POST['salary_type']){
				$_POST['minsalary']=$_POST['maxsalary']=0;
			}

			if($_POST['id']&&$_POST['uid']==''){
				$job=$this->obj->DB_select_once("company_job","`id`='".$_POST['id']."'","`uid`");
				$where['id']=$_POST['id'];
				unset($_POST['id']);
				if(!isset($_POST['is_graduate'])){
					$_POST['is_graduate']=0;
				}
				$this->obj->update_once("company_job",$_POST,$where);
				$this->obj->DB_update_all("company","`lastupdate`='".time()."'","`uid`='".$job['uid']."'");
				$this->ACT_layer_msg("职位(ID:".$where['id'].")修改成功！",9,$lasturl,2,1);
			}else if($_POST['uid']){
				$company=$this->obj->DB_select_once("company","`uid`='".$_POST['uid']."'","name");
				$statis=$this->obj->DB_select_once("company_statis","`uid`='".$_POST['uid']."'","`vip_etime`,`job_num`,`integral`,`rating_type`");

				

				if($statis['vip_etime']>time() || $statis['vip_etime']=="0"){
					if($statis['rating_type']==1){
					
						if($statis['job_num']<1){
 							$this->ACT_layer_msg("该会员发布职位用完！",8,"index.php?m=admin_company_job");
							
						}else{
							$this->obj->DB_update_all("company_statis","`job_num`=`job_num`-1","`uid`='".$_POST['uid']."'");
						}
					}
				}else{

					$this->ACT_layer_msg("该会员套餐已到期！",8,"index.php?m=admin_company_job");

				}
				$_POST['com_name']=$company['name'];
				$_POST['welfare']=$company['welfare'];
				$_POST['sdate']=time();
				if(!isset($_POST['is_graduate'])){
					$_POST['is_graduate']=0;
				}
				$id=$this->obj->insert_into("company_job",$_POST);
				if($id){
					$this->obj->DB_update_all("company","`jobtime`='".time()."'","`uid`='".$_POST['uid']."'");
					$this->ACT_layer_msg( "职位(ID:".$id.")发布成功！",9,'index.php?m=admin_company_job&c=show&uid='.$_POST['uid'],2,1);
				}else{
					$this->ACT_layer_msg( "职位发布失败！",8,'index.php?m=admin_company_job&c=show&uid='.$_POST['uid'],2,1);
				}
			}
		}
		$this->yunset("uid",$_GET['uid']);
		$this->yuntpl(array('admin/admin_company_job_show'));
	}
	function lockinfo_action(){
		$userinfo = $this->obj->DB_select_once("company_job","`id`=".$_POST['id'],"`statusbody`");
		echo $userinfo['statusbody'];die;
	}
	function status_action(){

		 extract($_POST);
		 $id = @explode(",",$pid);
		 if(is_array($id)){
			foreach($id as $value){
				if($value){
					$idlist[] = $value;
					$data[] = $this->shjobmsg($value,$status,$statusbody);
				}
			}
			if($data!=""){
			    $push = $this->getPush();
			    $notice = $this->MODEL('notice');
			    foreach($data as $key=>$value){
			        $result = $notice->sendEmailType($value);
			        $result = $notice->sendSMSType($value);
			        if ($push){
			            if ($value['clientid']&& $value['clientid']!=''){
			                $puser = array('clientid'=>$value['clientid'],'deviceToken'=>$value['deviceToken']);
			                if ($value['type']=='zzshtg'){
			                    $content = mb_substr('职位：'.$value['jobname'].'审核通过', 0, 24, 'UTF-8');
			                }elseif ($value['type']=='zzshwtg'){
			                    $content = mb_substr('职位：'.$value['jobname'].'审核未通过', 0, 24, 'UTF-8');
			                }
			                $this->makePush($this->config['sy_webname'], $content, $puser, $push);
			            }
			        }
			    }
			}
			$aid = @implode(",",$idlist);
			$id=$this->obj->DB_update_all("company_job","`state`='$status',`statusbody`='".$statusbody."',`lastupdate`='".time()."'","`id` IN ($aid)");
			if($id){ 

				$Weixin=$this->MODEL('weixin');
				$sendInfo['jobid'] = $idlist;
				$sendInfo['state'] = $status;
				$sendInfo['statusbody'] = $statusbody; 
				$Weixin->sendWxJobStatus($sendInfo);
			}
			$id?$this->ACT_layer_msg("职位审核(ID:".$aid.")设置成功！",9,$_SERVER['HTTP_REFERER'],2,1):$this->ACT_layer_msg("设置失败！",8,$_SERVER['HTTP_REFERER']);
		}else{
			$this->ACT_layer_msg("非法操作！",8,$_SERVER['HTTP_REFERER']);
		}
	}
	function saveclass_action(){
		extract($_POST);
//		if($hy==""){
//			$this->ACT_layer_msg("请选择行业类别！",8,$_SERVER['HTTP_REFERER']);
//		}
		if($job1==""){
			$this->ACT_layer_msg("请选择职位类别！",8,$_SERVER['HTTP_REFERER']);
		}
		$id=$this->obj->DB_update_all("company_job","`hy`='$hy',`job1`='$job1',`job1_son`='$job1_son',`job_post`='$job_post'","`id` IN ($jobid)");
		$id?$this->ACT_layer_msg("职位类别(ID:".$jobid.")修改成功！",9,$_SERVER['HTTP_REFERER'],2,1):$this->ACT_layer_msg("修改失败！",8,$_SERVER['HTTP_REFERER']);
	}
	function jobclass_action(){
		include(PLUS_PATH."industry.cache.php");
		include(PLUS_PATH."job.cache.php");
		if(is_array($job_type[$_POST['val']])&&$job_type[$_POST['val']]){
			foreach($job_type[$_POST['val']] as $val){
				$html.="<option value='".$val."'>".$job_name[$val]."</option>";
			}
		}else{$html.="<option value=''>暂无分类</option>";}
		echo $html;
	}
	function shjobmsg($jobid,$yesid,$statusbody){
	    $data=array();
	    $comarr=$this->obj->DB_select_once("company_job","`id`='".$jobid."'","uid,name");
	    if($yesid==1){
	        $data['type']="zzshtg";
	        $this->send_dingyue($jobid,2);
	    }elseif($yesid==3){
	        $data['type']="zzshwtg";
	    }
	    if($data['type']!=""){
	        $select = 'a.email,a.moblie,a.uid,b.name';
	        if($this->config['sy_push_open']==1){
	            $select.=',a.clientid,a.deviceToken';
	        }
	        $uid=$this->obj->DB_select_alls("member","company","a.`uid`='".$comarr['uid']."' and a.`uid`=b.`uid`",$select);
	        $data['uid']=$uid[0]['uid'];
	        $data['name']=$uid[0]['name'];
	        $data['email']=$uid[0]['email'];
	        $data['moblie']=$uid[0]['moblie'];
	        $data['jobname']=$comarr['name'];
	        $data['date']=date("Y-m-d H:i:s");
	        $data['status_info']=$statusbody;
	        $data['clientid']=$uid[0]['clientid'];
	        $data['deviceToken']=$uid[0]['deviceToken'];
	        return $data;
	    }
	}
	function ctime_action(){
		extract($_POST);
		$id=@explode(",",$jobid);
		
		if(!empty($id)){
			$posttime=$endtime*86400;
			$time=time()+$posttime;
			
			
			foreach($id as $value){
				$row=$this->obj->DB_select_once("company_job","`id`='".$value."'");
				if($row['state']==2 || $row['edate']<time()){
					$time=time()+$posttime;
					$id=$this->obj->DB_update_all("company_job","`edate`='".$time."',`state`='1'","`id`='".$value."'");
				}else{
					$time=$row['edate']+$posttime;
					$id=$this->obj->DB_update_all("company_job","`edate`='".$time."'","`id`='".$value."'");
				}
			}
			
			$id?$this->ACT_layer_msg("职位延期(ID:".$jobid.")设置成功！",9,$_SERVER['HTTP_REFERER'],2,1):$this->ACT_layer_msg("设置失败！",8,$_SERVER['HTTP_REFERER']);
		}else{
			$this->ACT_layer_msg("非法操作！",8,$_SERVER['HTTP_REFERER']);
		}
	}
	function xuanshang_action(){
		if($_POST['s']==1){
			$id=$this->obj->DB_update_all("company_job","`xsdate`= null","`id`='".intval($_POST['pid'])."'");
		}else{
			$info=$this->obj->DB_select_once("company_job","`id`='".intval($_POST['pid'])."'","`xsdate`");
			$xsdays=intval($_POST['xsdays']);
			$time=$xsdays*86400;
			if($info['xsdate']>time()){
				$id=$this->obj->DB_update_all("company_job","`xsdate`=`xsdate`+'".$time."'","`id`='".intval($_POST['pid'])."'");
			}else{ 
				$xsdate=time()+$time;
				$id=$this->obj->DB_update_all("company_job","`xsdate`='".$xsdate."'","`id`='".intval($_POST['pid'])."'");
			} 
		}
		//$id?$this->layer_msg("职位置顶(ID:".$_POST['pid'].")设置成功！",9,$_SERVER['HTTP_REFERER'],2,1):$this->layer_msg("设置失败！",8,$_SERVER['HTTP_REFERER']);
		if($id){
			echo "<script>alert('修改成功');parent.location.reload();</script>";exit();
		}else{
			echo "<script>alert('修改失败');parent.location.reload();</script>";exit();
		}
	}
	function recommend_action(){
		extract($_POST);
		if($addday<1&&$s==''){$this->ACT_layer_msg("推荐天数不能为空！",8);}
		$addtime = 86400*$addday;
		if($pid){
			if($s==1){
				$this->obj->DB_update_all("company_job","`rec_time`='0',`rec`='0'","`id`='$pid'");
			}elseif($eid>time()){
				$this->obj->DB_update_all("company_job","`rec_time`=`rec_time`+$addtime,`rec`='1'","`id`='$pid'");
			}else{
				$time=time()+$addtime;
				$this->obj->DB_update_all("company_job","`rec_time`='".$time."',`rec`='1'","`id`='$pid'");
			}
			$this->ACT_layer_msg("职位推荐(ID:".$pid.")设置成功！",9,$_SERVER['HTTP_REFERER'],2,1);
		}
		if(!empty($codearr)){
			if($s==1){
				$this->obj->DB_update_all("company_job","`rec_time`='0',`rec`='0'","`id` in (".$codearr.")");
				$this->ACT_layer_msg("取消职位推荐设置成功！",9,$_SERVER['HTTP_REFERER'],2,1);
			}else{
				$list=$this->obj->DB_select_all("company_job","`id` in (".$codearr.")","`id`,`rec_time`");
                if(is_array($list)){
                	foreach($list as $v){
                        if($v['rec_time']<time()){
                       	    $gid[]=$v['id'];   
                        }else{
                       	    $mid[]=$v['id'];   
                        }
                	}
                	$guoqi=@implode(",",$gid);
                	$meiguo=@implode(",",$mid);
                	if($guoqi!=""){
						$time=time()+$addtime;
				        $this->obj->DB_update_all("company_job","`rec_time`=".$time.",`rec`='1'","`id` in (".$guoqi.")");
                	}elseif($meiguo!=""){
				        $this->obj->DB_update_all("company_job","`rec_time`=`rec_time`+$addtime,`rec`='1'","`id` in (".$meiguo.")");
                	}
                	$this->ACT_layer_msg("职位推荐设置成功！",9,$_SERVER['HTTP_REFERER'],2,1);
                }
			}
		}

	}
	function urgent_action(){
		extract($_POST);
		if($addday<1&&$s==''){$this->ACT_layer_msg("紧急天数不能为空！",8);}
		$addtime = 86400*$addday;
		if($pid){
			if($s==1){
				$this->obj->DB_update_all("company_job","`urgent_time`='0',`urgent`='0'","`id`='$pid'");
			}elseif($eid>time()){
				$this->obj->DB_update_all("company_job","`urgent_time`=`urgent_time`+$addtime,`urgent`='1'","`id`='$pid'");
			}else{
				$this->obj->DB_update_all("company_job","`urgent_time`=".time()."+$addtime,`urgent`='1'","`id`='$pid'");
			}
			$this->ACT_layer_msg("紧急招聘(ID:".$pid.")设置成功！",9,$_SERVER['HTTP_REFERER'],2,1);
		}
		if(!empty($codeugent)){
			if($s==1){
				$this->obj->DB_update_all("company_job","`urgent_time`='0',`urgent`='0'","`id` in (".$codeugent.")");
				$this->ACT_layer_msg("取消职位紧急设置成功！",9,$_SERVER['HTTP_REFERER'],2,1);
			}else{
				$code_ugent=@explode(",",$codeugent);
				if(is_array($code_ugent)){
					foreach($code_ugent as $k=>$v){
						$r_time[$v]=$this->obj->DB_select_once("company_job","`id`='".$v."'","`urgent_time`");
					}
				}
                if(is_array($r_time)){
                	$ti=time();
                	foreach($r_time as $ke=>$va){
                       if($va['urgent_time']<$ti){
                       	    $g_id[]=$ke;   
                       }else{
                       	    $m_id[]=$ke;   
                       }
                	}
                	$guoqi=@implode(",",$g_id);
                	$meiguo=@implode(",",$m_id);
                	if($g_id){
				        $this->obj->DB_update_all("company_job","`urgent_time`=".time()."+$addtime,`urgent`='1'","`id` in (".$guoqi.")");
                	}elseif($m_id){
				       $this->obj->DB_update_all("company_job","`urgent_time`=`urgent_time`+$addtime,`urgent`='1'","`id` in (".$meiguo.")");
                	}
                	$this->ACT_layer_msg("职位紧急设置成功！",9,$_SERVER['HTTP_REFERER'],2,1);
                }
			}
		}

	}
	function del_action(){
		$this->check_token();
	    if($_GET['del']||$_GET['id']){
    		if(is_array($_GET['del'])){
    			$layer_type=1;
				$del=@implode(',',$_GET['del']);
	    	}else{
	    		$layer_type=0;
	    		$del=$_GET['id'];
	    	}
			$this->obj->DB_delete_all("user_entrust_record","`jobid` in (".$del.")","");
			$this->obj->DB_delete_all("company_job","`id` in (".$del.")","");
			$this->obj->DB_delete_all("company_job_link","`jobid` in (".$del.")","");
			$this->obj->DB_delete_all("userid_msg","`jobid` in (".$del.")","");
			$this->obj->DB_delete_all("userid_job","`job_id` in (".$del.")","");
			$this->obj->DB_delete_all("fav_job","`job_id` in (".$del.")","");
			$this->obj->DB_delete_all("look_job","`jobid` in (".$del.")","");


			$this->obj->DB_delete_all("report","`usertype`=1 and `type`=0 and `eid` in (".$del.")","");
			$this->layer_msg("职位(ID:".$del.")删除成功！",9,$layer_type,$_SERVER['HTTP_REFERER']);
    	}else{
			$this->layer_msg("请选择您要删除的信息！",8,1);
    	}
	}
	function refresh_action()
	{
		$list=$this->obj->DB_select_all("company_job","`id` in (".$_POST['ids'].")","`uid`");
		if(is_array($list)){
			foreach($list as $v){
				$uid[]=$v['uid'];
			} 
			$this->obj->DB_update_all("company","`lastupdate`='".time()."'","`uid` in (".@implode(",",$uid).")");
		}
		$this->obj->DB_update_all("company_job","`lastupdate`='".time()."'","`id` in (".$_POST['ids'].")");
		$this->MODEL('log')->admin_log("职位(ID".$_POST['ids']."刷新成功");
	}
	function xls_action(){
		include(CONFIG_PATH."db.data.php");		
		$this->yunset("arr_data",$arr_data);
		if($_POST['pid']){
		    if( $_POST['keyword'] ){
                $keyword = $_POST['keyword'];
                if( $_POST['status'] ){
					if($_POST['status'] == 3){
						$list=$this->obj->DB_select_all("company_job","`id` in (".$_POST["pid"].") and CONCAT(`com_name`,`name`) like '%".trim($keyword)."%' and `xsdate`> '".time()."'",'*');

					}else{
						$list=$this->obj->DB_select_all("company_job","`id` in (".$_POST["pid"].") and CONCAT(`com_name`,`name`) like '%".trim($keyword)."%' and `status`= '".$_POST['status']."'",'*');
					}
                }else{
                    $list=$this->obj->DB_select_all("company_job","`id` in (".$_POST["pid"].") and CONCAT(`com_name`,`name`) like '%".trim($keyword)."%'",'*');
                }
            }else{
                if( $_POST['status'] ) {
					if($_POST['status'] == 3){
						$list = $this->obj->DB_select_all("company_job", "`id` in (" . $_POST["pid"] . ") and `xsdate`> '".time()."'", '*');
					}else{
						$list = $this->obj->DB_select_all("company_job", "`id` in (" . $_POST["pid"] . ") and `status`= '".$_POST['status']."'", '*');
					}
                }else{
                    $list = $this->obj->DB_select_all("company_job", "`id` in (" . $_POST["pid"] . ")", '*');
                }
            }
		}else{
            if( $_POST['keyword'] ){
                $keyword = $_POST['keyword'];
                if( $_POST['status'] ){
					if($_POST['status'] == 3){
						$list=$this->obj->DB_select_all("company_job","1 and CONCAT(`com_name`,`name`) like '%".trim($keyword)."%' and `xsdate`> '".time()."'",'*');
					}else{
						$list=$this->obj->DB_select_all("company_job","1 and CONCAT(`com_name`,`name`) like '%".trim($keyword)."%' and `status`= '".$_POST['status']."'",'*');
					}
                }else{
                    $list=$this->obj->DB_select_all("company_job","1 and CONCAT(`com_name`,`name`) like '%".trim($keyword)."%'",'*');
                }
            }else{
                if( $_POST['status'] ) {
					if($_POST['status'] == 3){
						$list = $this->obj->DB_select_all("company_job", "`xsdate`> '".time()."'", '*');
					}else{
						$list = $this->obj->DB_select_all("company_job", "`status`= '".$_POST['status']."'", '*');
					}
                }else{
                    $list=$this->obj->DB_select_all("company_job"," 1 ",'*');
                }
            }

        }
        if(!empty($list)){
            foreach($list as $k=>$v){

                $job_brights = array();
                if($v['bright']!=""){
                    include PLUS_PATH."/com.cache.php";
                    $job_bright=@explode(",",$v['bright']);
                    foreach($job_bright as $val){
                        $job_brights[]=$comclass_name[$val];
                    }
                    $list[$k]['bright']=@implode(",",$job_brights);
                }

                $welfare_others = array();
                if($v['welfare_other']!=""){
                    include PLUS_PATH."/com.cache.php";
                    $welfare_other=@explode(",",$v['welfare_other']);
                    foreach($welfare_other as $val_other){
                        $welfare_others[]=$comclass_name[$val_other];
                    }
                    $list[$k]['welfare_other']=@implode(",",$welfare_others);
                }

                if( $v['nature'] == 1 ){//1全职，2兼职
                    $list[$k]['nature']='全职';
                }else{
                    $list[$k]['nature']='兼职';
                }
                $list[$k]['sex']=$arr_data['sex'][$v['sex']];
            }
            $this->yunset("list",$list);
            $this->yunset($this->MODEL('cache')->GetCache(array('city','hy','com','job')));

            $this->MODEL('log')->admin_log("导出职位信息");
            header("Content-Type: application/vnd.ms-excel");
            header("Content-Disposition: attachment; filename=".date('Y-m-d H')."职位表.xls");
            $this->yuntpl(array('admin/admin_job_xls'));
        }
	}
	function checkstate_action(){
		if($_POST['id'] && $_POST['state']){
			$this->obj->DB_update_all("company_job","`status`='".$_POST['state']."'","`id`='".$_POST['id']."'");
		}
		echo 1;
	}
	function matching_action(){
	    if($_GET['id']){
	        $id=intval($_GET['id']);
	        $this->yunset($this->MODEL('cache')->GetCache(array('city')));
	        $where = "status<>'2' and `r_status`<>'2' and `job_classid`<>'' and `open`='1' and `defaults`='1'";
	        $JobM=$this->MODEL('job');
	        $jobinfo=$JobM->GetComjobOne(array('id'=>$id),array('field'=>'uid,job1,cityid'));
	        $this->yunset('comid',$jobinfo['uid']);
	        if($jobinfo){
	            $where .="and `cityid`='".$jobinfo['cityid']."'";
	        }
	        include PLUS_PATH."job.cache.php";
	        if($jobinfo['job1']){
	            $joball=$job_type[$jobinfo['job1']];
	            foreach($job_type[$jobinfo['job1']] as $v){
	                $joball[]=@implode(",",$job_type[$v]);
	            }
	            $job_classid=@implode(",",$joball);
	        }
	        if(!empty($job_classid)){
	            $classid=@explode(",",$job_classid);
	            foreach($classid as $value){
	                $jobclass[]="FIND_IN_SET('".$value."',job_classid)";
	            }
	            $classid=@implode(" or ",$jobclass);
	            $where .= " AND ($classid)";
	        }
			$record=$this->obj->DB_select_all("user_entrust_record","`jobid`='".$id."'");
			foreach($record as $v){
				$eids[]=$v['eid'];
			}
			$black=$this->obj->DB_select_all("blacklist","`p_uid`='".$jobinfo['uid']."'");
			foreach($black as $v){
			    $buids[]=$v['c_uid'];
			}
	        $where.=" and `id` not in(".pylode(',',$eids).")";
	        $where.=" and `uid` not in(".pylode(',',$buids).")";
	        $where.="order by `lastupdate` desc";
	        $urlarr["page"]="{{page}}";
	        $pageurl=Url('admin_company_job&c=matching&id='.$id.'',$urlarr,'admin');
	        $rows=$this->get_page("resume_expect",$where,$pageurl,$this->config['sy_listnum'],'`id`,`uid`,`uname`,`job_classid`,`provinceid`,`cityid`');
			foreach ($rows as $key=>$val){
	            $job_classid=explode(",",$val['job_classid']);
				$jobname=array();
				if(is_array($job_classid)){
					foreach($job_classid as $val){
						$jobname[]=$job_name[$val];
					}
				}
				$rows[$key]['job_name']=implode(",",$jobname);
	        }
	        $this->yunset('resumes',$rows);
	        $this->yuntpl(array('admin/admin_matching'));
	    }
	}
}
?>